#ifndef _LIBSNES_CLR_H
#define _LIBSNES_CLR_H

#include <stdint.h>
#include <windows.h>

#ifdef __cplusplus
extern "C" {
#endif

// ============
// CLR specific
// ============

void clr_snes_get_buffer_lengths(unsigned *video, unsigned *audio);

typedef void (*clr_snes_frame_complete_t)(const uint16_t *video_data, unsigned width, unsigned height,
                                          const uint32_t *audio_data, unsigned count);

void clr_snes_set_frame_complete(clr_snes_frame_complete_t callback);
HANDLE clr_snes_enable_synced_input(HANDLE managed_auto_event);
void clr_snes_set_input_state(unsigned port, unsigned index, uint16_t buttons, int32_t coords);

// ================
// libsnes wrappers
// ================

unsigned clr_snes_library_revision_major(void);
unsigned clr_snes_library_revision_minor(void);

void clr_snes_set_controller_port_device(bool port, unsigned device);

void clr_snes_init(void);
void clr_snes_term(void);
void clr_snes_power(void);
void clr_snes_reset(void);
void clr_snes_run(void);

unsigned clr_snes_serialize_size(void);
bool clr_snes_serialize(uint8_t *data, unsigned size);
bool clr_snes_unserialize(const uint8_t *data, unsigned size);

void clr_snes_cheat_reset(void);
void clr_snes_cheat_set(unsigned index, bool enabled, const char *code);

void clr_snes_load_cartridge_normal(
  const char *rom_xml, const uint8_t *rom_data, unsigned rom_size
);

void clr_snes_load_cartridge_bsx_slotted(
  const char *rom_xml, const uint8_t *rom_data, unsigned rom_size,
  const char *bsx_xml, const uint8_t *bsx_data, unsigned bsx_size
);

void clr_snes_load_cartridge_bsx(
  const char *rom_xml, const uint8_t *rom_data, unsigned rom_size,
  const char *bsx_xml, const uint8_t *bsx_data, unsigned bsx_size
);

void clr_snes_load_cartridge_sufami_turbo(
  const char *rom_xml, const uint8_t *rom_data, unsigned rom_size,
  const char *sta_xml, const uint8_t *sta_data, unsigned sta_size,
  const char *stb_xml, const uint8_t *stb_data, unsigned stb_size
);

void clr_snes_load_cartridge_super_game_boy(
  const char *rom_xml, const uint8_t *rom_data, unsigned rom_size,
  const char *dmg_xml, const uint8_t *dmg_data, unsigned dmg_size
);

void clr_snes_unload_cartridge(void);

bool clr_snes_get_region(void);
uint8_t* clr_snes_get_memory_data(unsigned id);
unsigned clr_snes_get_memory_size(unsigned id);

#ifdef __cplusplus
}
#endif

#endif
